package com.ljl.mvvmdemo.ui.dialog

import android.os.Bundle
import android.text.TextUtils
import com.ljl.mvvmdemo.GlideApp
import com.ljl.mvvmdemo.R
import com.ljl.mvvmdemo.databinding.DialogLoadingBinding
import com.ljl.mvvmdemo.util.TIP
import com.ljl.mvvmdemo.viewmodel.LoadingViewModel

/**
 * 等待交互弹窗
 * created by luojialun on 2024/7/30
 */
class LoadingDialog : BaseDialog<DialogLoadingBinding, LoadingViewModel>() {

    private var tip: String = ""

    override fun getLayoutId(): Int {
        return R.layout.dialog_loading
    }

    override fun initParam() {
        super.initParam()
        arguments?.let {
            tip = it.getString(TIP, "")
        }
    }

    override fun initView() {
        viewModel.tipOB.set(tip)
        if (TextUtils.isEmpty(tip)) {
            viewModel.tipVisibleOB.set(false)
        } else {
            viewModel.tipVisibleOB.set(true)
        }
        context?.let {
            GlideApp.with(it).load(R.mipmap.loading).into(binding.ivLoading)
        }
    }
}

fun LoadingDialog(tip: String = ""): LoadingDialog {
    val args = Bundle()
    args.putString(TIP, tip)
    val loadingDialog = LoadingDialog()
    loadingDialog.arguments = args
    return loadingDialog
}